define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'gymnasium/index' + location.search,
                    add_url: 'gymnasium/add',
                    edit_url: 'gymnasium/edit',
                    del_url: 'gymnasium/del',
                    multi_url: 'gymnasium/multi',
                    import_url: 'gymnasium/import',
                    table: 'gymnasium',
                }
            });

            var table = $("#table");

            table.on('post-common-search.bs.table', function (event, table) {
                $('ul.nav-tabs li a[data-value="0"]').trigger('click');
                $(".form-commonsearch select[name=status]").val("0");
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                showSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5'),"6":__('Type 6')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name'), operate: "LIKE"},
                        {field: 'logo_image', title: __('Logo_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'thumb_image', title: __('Thumb_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'share_images', title: __('Share_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'phone', title: __('Phone')},
                        {field: 'address', title: __('Address')},
                        {field: 'area', title: __('Area'), operate: false},
                        // {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        // {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'business_hours', title: __('Business_hours')},
                        // {field: 'license_image', title: __('License_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'card_up_image', title: __('Card_up_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'card_down_image', title: __('Card_down_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'percentage', title: __('Percentage'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        // {field: 'likes', title: __('Likes')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"), function(data, ret){
                    window.location.reload();
                    Toastr.success(data);
                });
            }
        }
    };
    return Controller;
});
